<%--
  Created by IntelliJ IDEA.
  User: cyh_it
  Date: 2025/7/16
  Time: 11:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <base href="${pageContext.request.contextPath}/" />
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <style>
        /*定义类名为.thead-blue的样式*/
        .thead-blue {
            color: #fff;
            font-weight: bold;
            background-color: #337ab7;
        }
    </style>
    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.js"></script>
</head>
<body>

<!-- 搜索 -->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">员工搜索</h4>
    </div>
    <div class="panel-body">
        <form action="hr/emp/listEmpVo" id="seachform" method="post" class="form-horizontal" role="form">
            <div class="form-group">
                <div class="col-md-5">
                    <label for="empName" class="col-md-4 control-label">员工名称</label>
                    <div class="col-md-8">
                        <input type="text" id="empName" name="empName"
                               class="form-control" placeholder="请输入员工名称" value="${employee.empName}">
                        <input type="hidden" name="page" id="page" value="1">
                        <input type="hidden" name="pageSize" id="pageSize" value="5">
                    </div>
                </div>
                <div class="col-md-5">
                    <label for="phone" class="col-md-4 control-label">员工电话</label>
                    <div class="col-md-8">
                        <input type="text" id="phone" name="phone"
                               class="form-control" placeholder="请输入员工电话"  value="${employee.phone}">
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="col-md-12">
                        <a type="button" href="hr/emp/toAddEmp" class="btn btn-info">添加员工</a>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-5">
                    <label for="deptid" class="col-md-4 control-label">所属部门</label>
                    <div class="col-md-8">
                        <select name="deptid" class="form-control" id="deptid">
                            <option value="">--请选择--</option>

                            <c:forEach items="${departments}" var="department">
                                <option value="${department.oid}" ${department.oid==employee.deptid? 'selected':''}>${department.deptName}</option>
                            </c:forEach>

                        </select>
                    </div>
                </div>
                <div class="col-md-5">
                    <label for="jobid" class="col-md-4 control-label">员工职位</label>
                    <div class="col-md-8">
                        <select name="jobid" class="form-control" id="jobid">
                            <option value="">--请选择--</option>

                            <c:forEach items="${jobs}" var="job">
                                <option value="${job.oid}" ${job.oid==employee.jobid ? 'selected':''}>${job.name}</option>
                            </c:forEach>

                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-5">
                    <label for="sex" class="col-md-4 control-label">员工性别</label>
                    <div class="col-md-8">
                        <select name="sex" class="form-control" id="sex">
                            <option value="">--请选择--</option>
                            <option value="M" ${employee.sex=='M' ? 'selected':''}>男</option>
                            <option value="F" ${employee.sex=='F' ? 'selected':''} >女</option>
                        </select>
                    </div>
                </div>
                <div class="col-md-5">
                    <label for="degree" class="col-md-4 control-label">员工学历</label>
                    <div class="col-md-8">
                        <select name="degree" class="form-control" id="degree">
                            <option value="">--请选择--</option>

                            <c:forEach items="${degrees}" var="degree">
                                <option value="${degree.oid}" ${degree.oid==employee.degree ? 'selected':''}>${degree.name}</option>
                            </c:forEach>

                        </select>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="col-md-12">
                        <button type="button" onclick="searchBtn()" class="btn btn-success">搜索员工</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- 列表 -->
<div class="panel panel-primary">
    <table class="table table-bordered table-hover">
        <thead>
        <tr class="thead-blue" align="center">
            <td>员工编号</td>
            <td>员工姓名</td>
            <td>员工性别</td>
            <td>所属部门</td>
            <td>员工职位</td>
            <td>员工学历</td>
            <td>员工电话</td>
            <td>员工状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>

        <c:forEach items="${empVoIPage.records}" var="empVo">
        <tr align="center">
                <td>${empVo.oid}</td>
                <td>${empVo.empName}</td>
                <td>
                    <c:choose>
                        <c:when test="${empVo.sex=='M'}">男</c:when>
                        <c:when test="${empVo.sex=='F'}">女</c:when>
                        <c:otherwise>性别非法</c:otherwise>
                    </c:choose>
                </td>
                <td>${empVo.deptName}</td>
                <td>${empVo.jobName}</td>
                <td>${empVo.degreeName}</td>
                <td>${empVo.phone}</td>
                <td>${empVo.state=='Y' ? '在职':'离职'}</td>

            <td>
                <a type="button" href="hr/emp/empInfo?oid=${empVo.oid}" class="btn btn-info btn-xs">详情</a>
                <a type="button" href="hr/emp/toUpdateEmp?oid=${empVo.oid}" class="btn btn-primary btn-xs">修改</a>

                <c:choose>
                    <c:when test="${empVo.state=='Y'}">
                        <button onclick="updateEmpState(this,${empVo.oid})" value="N"  class="btn btn-warning btn-xs" type="button">离职</button>
                    </c:when>
                    <c:otherwise>
                        <button onclick="updateEmpState(this,${empVo.oid})" value="Y"  class="btn btn-success btn-xs" type="button">复职</button>
                    </c:otherwise>
                </c:choose>

                <button type="button" onclick="deleteEmp(${empVo.oid})" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#confirmModal" >删除</button>

                <button onclick="addAdjustment(${empVo.oid})" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#addadjustmentModal" type="button" >调动</button>


                <a type="button" href="hr/zz-adjustment/adjustmentInfo?empid=${empVo.oid}" class="btn btn-info btn-xs">调动详情</a>
            </td>
        </tr>
        </c:forEach>


        </tbody>
    </table>
</div>

<!-- 分页 -->
<div class="input-group col-md-6 col-md-offset-3">
    <div class="row">
        <div class="btn-group">
            <button onclick="gotoPage(1,${empVoIPage.size})" class="btn btn-primary" type="button">首页</button>

            <c:choose>
                <c:when test="${empVoIPage.current<=1}">
                    <button class="btn btn-primary disabled" type="button">上一页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary " onclick="gotoPage(${empVoIPage.current-1},${empVoIPage.size})" type="button">上一页</button>
                </c:otherwise>
            </c:choose>

            <button class="btn btn-primary disabled" type="button">当前第${empVoIPage.current}/${empVoIPage.pages}页</button>

            <div class="btn-group">
                <button type="button" class="btn btn-primary dropdown-toggle"
                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    每页显示${empVoIPage.size}条 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li><a href="javascript:gotoPage(1,5)">每页显示5条</a></li>
                    <li><a href="javascript:gotoPage(1,10)">每页显示10条</a></li>
                    <li><a href="javascript:gotoPage(1,15)">每页显示15条</a></li>
                    <li><a href="javascript:gotoPage(1,20)">每页显示20条</a></li>
                </ul>
            </div>

            <button class="btn btn-primary disabled" type="button">共${empVoIPage.total}条记录</button>

            <c:choose>
                <c:when test="${empVoIPage.current<empVoIPage.pages}">
                    <button onclick="gotoPage(${empVoIPage.current+1},${empVoIPage.size})"  class="btn btn-primary" type="button">下一页</button>
                </c:when>
                <c:otherwise>
                    <button  class="btn btn-primary disabled" type="button">下一页</button>
                </c:otherwise>
            </c:choose>

            <button onclick="gotoPage(${empVoIPage.pages},${empVoIPage.size})" class="btn btn-primary" type="button">尾页</button>
        </div>
    </div>
</div>

<br><br><br>



<!-- 模态框（Modal） -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="confirmModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body">
                确认删除吗？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" id="subconfirm" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        $("#subconfirm").click(function(){
            deleteConfirm();
            $('#confirmModal').modal('hide');
        });
    });
</script>


<!-- 模态框（Modal） -->
<div class="modal fade" id="alertMsgModal" tabindex="-1" role="dialog" aria-labelledby="alertMsgModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xs">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="alertMsgModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body" id="alertmsg">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<link href="static/bootstrapvalidator/css/bootstrapValidator.css"
      rel="stylesheet">
<script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>


<%--员工调动模态框--%>
<div class="modal fade" id="addadjustmentModal" tabindex="-1"
     role="dialog" aria-labelledby="addadjustmentModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="addadjustmentModalLabel">员工调动</h4>
            </div>
            <form action="" class="form-horizontal" role="form" id="addAdjustmentForm">
                <div class="modal-body">
                    <div class="row">
                        <div class="form-group col-md-6">
                            <label class="col-md-4 control-label">员工编号</label>
                            <div class="col-md-8">
                                <input type="text" id="empidText" class="form-control" disabled>
                                <input type="hidden" name="empid" id="empid">
                            </div>
                        </div>

                        <div class="form-group col-md-6">
                            <label class="col-md-4 control-label">员工姓名</label>
                            <div class="col-md-8">
                                <input type="text" id="empNameText" class="form-control"
                                       disabled>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-6">
                            <label class="col-md-4 control-label">调动前部门</label>
                            <div class="col-md-8">
                                <input type="text" id="originDeptText" class="form-control"
                                       disabled> <input type="hidden" name="origindeptid"
                                                        id="origindeptid">
                            </div>
                        </div>

                        <div class="form-group col-md-6">
                            <label class="col-md-4 control-label">调动前职位</label>
                            <div class="col-md-8">
                                <input type="text" id="originJobText" class="form-control"
                                       disabled> <input type="hidden" name="originjobid"
                                                        id="originjobid">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-6">
                            <label for="destdeptid" class="col-md-4 control-label">调动后部门</label>
                            <div class="col-md-8">
                                <select name="destdeptid" class="form-control" id="destdeptid">
                                    <option value="">--请选择--</option>
                                    <c:forEach items="${departments}" var="department">
                                        <option value="${department.oid}">${department.deptName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="form-group col-md-6">
                            <label for="destjobid" class="col-md-4 control-label">调动后职位</label>
                            <div class="col-md-8">
                                <select name="destjobid" class="form-control" id="destjobid">
                                    <option value="">--请选择--</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-12">
                            <label for="reason" class="col-md-2 control-label">调动原因&nbsp;&nbsp;</label>
                            <div class="col-md-9">
								<textarea class="form-control" id="reason" name="reason"
                                          rows="5" placeholder="请输入调动原因"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" id="sub" class="btn btn-primary">确认调动</button>
                </div>
            </form>
        </div>
    </div>
</div>


<script>
    function addAdjustment(oid){

        $.getJSON("hr/emp/getEmpVoById",{"oid":oid}, function(emp) {
            $("#empidText").val(emp.oid);
            $("#empid").val(emp.oid);
            $("#empNameText").val(emp.empName);
            $("#originDeptText").val(emp.deptName);
            $("#origindeptid").val(emp.deptid);
            $("#originJobText").val(emp.jobName);
            $("#originjobid").val(emp.jobid);
            $('#addadjustmentModal').modal('show');

        });

    }
    $(document).ready(function() {

        // $.getJSON("dept/listDeptUseSelect", function(listdept) {
        //     var dept = $("#destdeptid")[0];
        //     dept.options.length = 1;
        //     for (var i = 0; i < listdept.length; i++) {
        //         var d = listdept[i];
        //         dept.options.add(new Option(d.deptName, d.oid));
        //     }
        // });

        $("#destdeptid").change(function() {
            $("#destjobid")[0].options.length = 1;
            if (this.value == "") {
                return;
            }
            $.getJSON("hr/zz-department-job/listDeptJobUseSelect", {
                deptid : this.value
            }, function(listjob) {
                var job = $("#destjobid")[0];
                job.options.length = 1;
                for (var i = 0; i < listjob.length; i++) {
                    var job1 = listjob[i];
                    job.options.add(new Option(job1.jobName, job1.jobid));
                }
            });

        });

        $("#sub").click(function() {
            $('#addAdjustmentForm').data("bootstrapValidator").validate();
            if($('#addAdjustmentForm').data("bootstrapValidator").isValid()){
                if($("#origindeptid").val()==$("#destdeptid").val() && $("#originjobid").val()==$("#destjobid").val()){
                    alert("调动岗位没有改变！");
                }else{
                    $.post("hr/zz-adjustment/addAdjustment", {
                        'empid' : $("#empid").val(),
                        'origindeptid' : $("#origindeptid").val(),
                        'destdeptid' : $("#destdeptid").val(),
                        'originjobid' : $("#originjobid").val(),
                        'destjobid' : $("#destjobid").val(),
                        'reason' : $("#reason").val()
                    }, function(s) {
                        if(s==true){
                            $("#alertmsg").text("调动成功!");
                            $('#alertMsgModal').modal('show');
                            document.location.href="hr/zz-adjustment/adjustmentInfo?empid="+$("#empid").val();
                        }else{
                            $("#alertmsg").text("调动失败!");
                            $("#addadjustmentModal").modal('hide');
                            $('#alertMsgModal').modal('show');
                        }
                    });
                }
            }
        });

        bindValidation();//绑定验证

        $('#addadjustmentModal').on('show.bs.modal', function() {
            $("#destdeptid").val("");
            $("#destjobid")[0].options.length = 1;
            $("#reason").val("");
        });

        $('#addadjustmentModal').on('hidden.bs.modal', function() {//监听modal消失
            $("#addAdjustmentForm").data('bootstrapValidator').destroy();
            $('#addAdjustmentForm').data('bootstrapValidator',null);
            bindValidation();//要重新绑定验证
            $("#addAdjustmentForm")[0].reset(); //将表单中的数据也清空

        })

    });

    function bindValidation(){
        $("#addAdjustmentForm").bootstrapValidator({
            message : 'This value is not valid',
            feedbackIcons : {/*input状态样式图片*/
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            fields : {
                destdeptid : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '请选择调动后部门'

                        }
                    }
                },
                destjobid : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '请选择调动后职位'

                        }
                    }
                },
                reason : {
                    validators : {
                        stringLength : {
                            max : 100,
                            message : '调动原因长度在100位以内'
                        }
                    }
                }
            },
            submitHandler : function(validator,form, submitButton) {
                validator.defaultSubmit();
            }
        });
    }
</script>






<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>

</body>
<script type="text/javascript">
    function gotoPage(page,pageSize){
        $("#page").val(page);
        $("#pageSize").val(pageSize);
        $("#seachform").submit();
    }
    function searchBtn(){
        $("#page").val(1);
        $("#seachform").submit();
    }

    var deleteoid;
    function deleteEmp(oid){
        deleteoid = oid;
    }
    function deleteConfirm(){
        $.get("hr/emp/deleteEmp",{"oid":deleteoid},function(s){
            if(s=='true'){
                document.location.href="hr/emp/listEmpVo";
            }else{
                $("#alertmsg").text("删除失败!当前员工正在使用!");
                $('#alertMsgModal').modal('show');
            }
        });
    }
    function updateEmpState(o,oid){
        var state=$(o).val();
        $.get("hr/emp/updateEmpStatue",{"oid":oid,'state':state},function(s){
            if(s=='true'){
                if(state=="Y"){
                    $(o).text("离职");
                    $(o).val("N");
                    $(o).removeClass("btn-success");
                    $(o).addClass("btn-warning");
                    $(o).parent().prev().text("在职");
                }else{
                    $(o).text("复职");
                    $(o).val("Y");
                    $(o).removeClass("btn-warning");
                    $(o).addClass("btn-success");
                    $(o).parent().prev().text("离职");
                }
            }else{
                $("#alertmsg").text("当前员工有待审工作未完成,无法离职!");
                $('#alertMsgModal').modal('show');
            }
        });
    }
</script>
</html>
